// 通用函数
const formatDate = date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const week = date.getDay()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()

    const nowDate = new Date()
    const nowYear = nowDate.getFullYear()
    //   return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
    // day = formatWeek(week)
    return year == nowYear ? (`${month}月${day}日 ${formatWeek(week)}`) : (`${year}年${month}月${day}日 ${formatWeek(day)}`)
}
const formatTime = date => {
    const hour = formatNumber(date.getHours())
    const minute = formatNumber(date.getMinutes())

    return hour +':'+ minute
}

const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : '0' + n
}
const weekArray = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']

const formatWeek = n => {
    return weekArray[n]
}

module.exports = {
    formatDate: formatDate,
    formatTime: formatTime
}